package com.atguigu.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ResponseUtil {

    public static void out(HttpServletResponse response, R r){
        ObjectMapper mapper=new ObjectMapper();

        response.setStatus(HttpStatus.OK.value()); // 设置响应状态码
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); //设置响应内容为JSON 并且是UTF-8格式
        try{
            mapper.writeValue(response.getWriter(),r);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
